package com.masiyi.minio.config;

import com.masiyi.minio.template.MinIOTemplate;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(value = MinIOProperties.class)
public class MinIOAutoConfiguration {


    @Autowired
    private MinIOProperties minIOProperties;


    @Bean
    public MinioClient getAliyun() {
        return MinioClient.builder().endpoint(minIOProperties.getUrl())
                .credentials(minIOProperties.getAccessKey(), minIOProperties.getSecretKey()).build();
    }

    @Bean
    public MinIOTemplate getAliyunTemplate(MinioClient minioClient) {
        return new MinIOTemplate(minioClient, minIOProperties);
    }

}
